var hasUpload = false;

$('#file').die().live('change', function() {
	if (hasUpload == true) {
		error("正在上传，请稍后再试！");
		return false;
	}
	var file = $("#file").val();
	if (file == null || file == "") {
		error("请选择图片！");
		return false;
	}
	if (!/\.(jpg|jpeg|png|gif|bmp)$/.test(file)) {
		error("图片的扩展名必须为：jpg,jpeg,png,gif,bmp");
		return false;
	}
	ajaxFileUpload('file');
});

function ajaxFileUpload(id) {
	hasUpload = true;
	$.ajaxFileUpload({
		url: path + "/file/uploadImg",
		type: 'post',
		secureuri: false,
		fileElementId: id,
		dataType: 'json',
		success: function(data) {
			if (data.statusCode == statusCode.ok) {
				success(data.message);
				var url = data.data.url;
				var html = '';
				html += '<div class="spant tr fl justify"><span class="justify">图片预览</div>';
				html += '<div style="position:relative;">';
				html += '<img src="' + path + url + '" onload="resizeImg(this, 160, 80)" onmouseover="originalImg(this)" onmouseout="resizeImg(this, 160, 80)" style="cursor:pointer;" />';
				html += '</div>';
				$("#li_img").html(html);
				$("input[name=url]").val(url);
			} else if (data.statusCode == statusCode.error) {
				error(data.message);
			}
			hasUpload = false;
		},
	    error: function(data, status, e){
			error(data.responseText);
			hasUpload = false;
	    }
	});
}